package org.rapidoid.docs.httpcustomauth;

import org.rapidoid.http.Self;
import org.rapidoid.setup.App;
import org.rapidoid.setup.My;
import org.rapidoid.setup.On;
import org.rapidoid.u.U;
import org.rapidoid.util.Tokens;

/**
 * @author caiwl
 * @date 2020/4/24 14:07
 */
public class Main {
    public static void main(String[] args) {
        App.bootstrap(args);

        My.rolesProvider((req, username) -> username.equals("bob") ? U.set("manager") : U.set());

        On.get("/hey").roles("manager").json(() -> U.map("msg", "ok"));

        // generate a token
        String token = Tokens.serialize(U.map("_user", "bob"));

        // demo request, prints {"msg":"ok"}
        Self.get("/hey?_token=" + token).print();
    }
}
